package main

import (
	"github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go"
	jaegercfg "github.com/uber/jaeger-client-go/config"
	"time"
)

// go发送多级嵌套span
func main() {
	cfg := jaegercfg.Configuration{
		Sampler: &jaegercfg.SamplerConfig{
			Type:  jaeger.SamplerTypeConst,
			Param: 1,
		},
		Reporter: &jaegercfg.ReporterConfig{
			LogSpans:           true,
			LocalAgentHostPort: "192.168.193.128:6831",
		},
		ServiceName: "ServiceName1",
	}
	tracer, closer, err := cfg.NewTracer(jaegercfg.Logger(jaeger.StdLogger))
	if err != nil {
		panic(err)
	}
	defer closer.Close()
	opentracing.SetGlobalTracer(tracer)
	parent := opentracing.StartSpan("parent")
	span1 := opentracing.StartSpan("fanqiechaodan-span1", opentracing.ChildOf(parent.Context()))
	time.Sleep(500 * time.Millisecond)
	span1.Finish()
	span2 := opentracing.StartSpan("fanqiechaodan-span2", opentracing.ChildOf(parent.Context()))
	time.Sleep(800 * time.Millisecond)
	span2.Finish()
	parent.Finish()
}
